<template>
  <div class="mobile">
    <div
      class="UserCenter"
      v-if="isShow"
    >
      <div class="page-title">
        {{ t('personalHomepage.pt1') }}
      </div>
      <div class="user">
        <div class="left">
          <div class="head-sculpture">
            <img
              :src="creatorInfo.avatar || creatorInfo.publishUserAvatar"
              alt=""
            />
          </div>
          <div class="name">
            <h2>{{ creatorInfo.customerName }}</h2>
            <p>{{ creatorInfo.label }}</p>
          </div>
        </div>
      </div>
      <el-scrollbar>
        <div class="scrollbar-flex-content router-list">
          <el-button
            v-for="item in mobileMenuList[type]"
            :key="item"
            type="primary"
          >
            <router-link :to="{ path: item.href }">
              {{ t(item.lable) }}
            </router-link>
          </el-button>
        </div>
      </el-scrollbar>
      <div class="g-con-m">
        <div
          class="body"
          v-if="Object.keys(infoObj).length != 0"
        >
          <el-card
            class="box-card"
            v-for="(item, index) in rightMessage[type]"
            :key="index"
          >
            <template #header>
              <div class="card-header">
                <span>{{ t(item.title) }}</span>
              </div>
            </template>
            <div class="card-body">
              <p>{{ item.sloganTxt || infoObj[item.firstKey][item.sloganKey] }}</p>
              <div class="bottom">
                <div v-if="item.firstKey != 'mainPageForumInfoVo'">
                  <ul class="card-item">
                    <li
                      v-for="(child, idx) in item.listData"
                      :key="idx"
                    >
                      <p class="num">{{ infoObj[item.firstKey][child.key] }}</p>
                      <p class="name">{{ t(child.name) }}</p>
                    </li>
                  </ul>
                </div>
                <div v-else>
                  <p
                    v-for="(child, idx) in item.listData"
                    :key="idx"
                    class="txt"
                  >
                    {{ infoObj[item.firstKey][child.key][0] }}
                    <span v-if="infoObj[item.firstKey][child.key][0]">{{ t(child.name) }}</span>
                  </p>
                </div>
              </div>
            </div>
          </el-card>
        </div>
      </div>
    </div>
    <router-view></router-view>
  </div>
</template>

<script setup>
import { ref, reactive, watch, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import useLogin from '@/stores/login'
import { useI18n } from 'vue-i18n'
import UserAction from '@/components/UserAction.vue'
import { mobileMenuList, rightMessage } from './common.js'
import { getInfo, getCustomerInfo } from '@/service/personalHomepage'

const { t, locale } = useI18n()
const router = useRouter()
const route = useRoute()

onMounted(() => {
  init()
})

watch(locale, () => {
  init()
})

const infoObj = ref({})
const store = useLogin()
const type = store.userInfo?.registerClassCode
const creatorInfo = ref({})

const isShow = computed(() => {
  return route.path === '/personalHomepage'
})

const init = () => {
  getInfo().then((res) => {
    infoObj.value = res.data
  })
  getCustomerInfo({ customerId: JSON.parse(localStorage.getItem('login')).userInfo.id }).then((res) => {
    creatorInfo.value = res.data
  })
}
</script>

<style scoped lang="scss">
.UserCenter {
  min-height: 1038px;
  background: rgba(245, 245, 245, 1);
  margin-bottom: -20px;

  .page-title {
    background: #252628;
    color: #fff;
    padding: 12px 20px;
    font-weight: bold;
  }

  .router-list {
    display: flex;
    flex-wrap: nowrap;
    background: #fff;
    padding-bottom: 10px;
    :deep(.el-button) {
      padding: 20px;
      margin-left: 20px;
      span {
        a {
          font-weight: 400;
          color: #ffffff;
        }
      }
    }
  }

  .user {
    width: 100%;
    padding: 20px;
    background: white;
    // height: 140px;
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;

      .head-sculpture {
        img {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          margin-right: 24px;
        }
      }

      .name {
        // padding-top: 24px;

        h2 {
          font-size: 16px;
          // font-weight: bold;
          color: #252628;
        }

        p {
          font-weight: 400;
          color: #9d9fa5;
          margin-top: 4px;
        }
      }
    }
  }

  .g-con-m {
    padding: 0;
    // padding-left: 28px;
    .body {
      width: 100%;
      .box-card {
        // padding-left: 30px;
        margin-top: 10px;
        min-height: 220px;
        display: flex;
        flex-direction: column;
        :deep(.el-card__header) {
          border-bottom: 2px solid black;
        }

        :deep(.card-header) {
          span {
            font-size: 16px;
          }

          font-family: Microsoft YaHei;
          font-weight: bold;
          color: #ca2a02;
        }

        .card-body {
          width: 100%;
          display: flex;
          flex-direction: column;
          flex: 1;
          p {
          }
          .bottom {
            width: 100%;
            display: flex;
            margin-top: 40px;

            div {
              width: 100%;
              .txt {
                width: 100%;
                background: rgba(245, 245, 245, 1);
                font-weight: 400;
                color: #6a6973;
                line-height: 44px;
                padding-left: 16px;
              }
            }
          }
        }

        .card-item {
          width: 100%;
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          gap: 20px;
          li {
            text-align: center;

            .num {
              font-size: 20px;
              font-weight: bold;
              color: #252628;
              line-height: 22px;
              margin-bottom: 8px;
            }

            .name {
              font-weight: 400;
              color: #6a6973;
              margin-top: 11px;
              word-break: keep-all;
            }
          }
        }
      }
    }
  }
}
</style>
